﻿<%@ include file="../include/top.jsp" %>
<%@ include file="../include/errorArea.jsp" %>
		
<link rel="stylesheet" href="${baseURL}/css/zTreeStyle/zTreeStyle.css" type="text/css">
<script type="text/javascript" src="${baseURL}/js/swfupload/swfupload.js"></script>
	<script type="text/javascript" src="${baseURL}/js/fileprogress.js"></script>
	<script type="text/javascript" src="${baseURL}/js/swfupload.queue.js"></script>
	<script  type="text/javascript" src="${baseURL}/js/jquery-1.8.3.js"></script>
<script type="text/javascript" src="${baseURL}/js/handlers.js"></script>
<script src="${baseURL}/shop/js/calendar.js"></script>
<script language="javascript" type="text/javascript" src="${baseURL}/js/jquery.ztree.all-3.5.min.js">
</script>
<SCRIPT type="text/javascript">
	var setting = {
		view: {
			dblClickExpand: false
		},
		data: {
			simpleData: {
				enable: true
			}
		},
		callback: {
			onClick: onClick
		}
	};

	var zNodes = ${treedata}; //后台返回的数据

	function onClick(e,treeId, treeNode) {
		var zTree = $.fn.zTree.getZTreeObj("treeDemo");
		zTree.expandNode(treeNode);

		//叶节点，并且不是第一层节点(第一层节点的pId是null)
		if(!treeNode.isParent && treeNode.pId!=null){
			nodes = zTree.getSelectedNodes();
			$("#selectedNodeName").attr("value", treeNode.name);
			$("#nodeId").attr("value", treeNode.id);
		}
	}

	function showMenu() {
		var cityObj = $("#selectedNodeName");
		var cityOffset = $("#selectedNodeName").offset();
		$("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");

		$("body").bind("mousedown", onBodyDown);
	}
	function hideMenu() {
		$("#menuContent").fadeOut("fast");
		$("body").unbind("mousedown", onBodyDown);
	}
	function onBodyDown(event) {
		if (!(event.target.id == "menuBtn" || event.target.id == "selectedNodeName" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) {
			hideMenu();
		}
	}

	$(document).ready(function(){
		$.fn.zTree.init($("#treeDemo"), setting, zNodes);
		
		var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
		var nodes = treeObj.getNodesByParam("id", "${formdata.nodeId}", null);
		if (nodes.length>0) {
			treeObj.selectNode(nodes[0]);
		}
	}
	);
	 var upload;
	  window.onload = function() {
		upload = new SWFUpload({
		// 处理文件上传的url
		upload_url: "${ctx}/supplierProduct/uploadPic",	// 路径写全，否则Firefox下会出现404错误。自由修改处一：处理文件上传的url路径，注意还要写全部
		// 上传文件限制设置
		file_size_limit : "10240",	// 10MB
		file_types : "*.jpg;*.gif;*.png",	//此处也可以修改成你想限制的类型，比如：*.doc;*.wpd;*.pdf
		file_types_description : "Image Files",
		file_upload_limit : "5",
		file_queue_limit : "5",

		// 事件处理设置（所有的自定义处理方法都在handler.js文件里）
		file_dialog_start_handler : fileDialogStart,
		file_queued_handler : fileQueued,
		file_queue_error_handler : fileQueueError,
		file_dialog_complete_handler : fileDialogComplete,
		upload_start_handler : uploadStart,
		upload_progress_handler : uploadProgress,
		upload_error_handler : uploadError,
		upload_success_handler : uploadSuccess,
		upload_complete_handler : uploadComplete,

		// 按钮设置
		button_image_url : "${baseURL}/js/swfupload/uploadbutton.png",	// 按钮图标
		button_placeholder_id : "spanButtonPlaceholder",
		button_width: 100,
		button_height: 25,
					
		// swf设置
		flash_url : "${baseURL}/js/swfupload/swfupload.swf",
					

		custom_settings : {
			progressTarget : "imgUploadProgress",
			cancelButtonId : "btnCancel",
			imgBoxObj : $("imgattachlist")
		},
					
			// Debug 设置
			debug: false
		});
	  }
	  function uploadStart()
	  {
	  this.addPostParam('supplierUser', '${sessionScope.supplierUser}');
	  }
		function fileDialogComplete(numFilesSelected, numFilesQueued, numFilesInQueue) {
			this.startUpload();
		}
		function uploadSuccess(file, serverData) {
			var item = $.parseJSON(serverData);
			var pic1=$("#productPic1").val();
			var pic2=$("#productPic2").val();
			var pic3=$("#productPic3").val();
			var pic4=$("#productPic4").val();
			var pic5=$("#productPic5").val();
			if(pic1=="")
				 $("#productPic1").val(item);
			else if(pic2=="")
			 	 $("#productPic2").val(item);
			else if(pic3=="")
				 $("#productPic3").val(item);
			else if(pic4=="")
				 $("#productPic4").val(item);
			else if(pic5=="")
				 $("#productPic5").val(item);
			if (this.getStats().files_queued === 0) {
			} else {
				this.startUpload();
			}
		}
		
		function iFrameHeight1() {   
			var ifm= document.getElementById("scfj");   
			var subWeb = document.frames ? document.frames["scfj"].document : ifm.contentDocument;   
			if(ifm != null && subWeb != null) {
			   ifm.height = subWeb.body.scrollHeight;
			}   
		}
		function delField(obj){
			var id= $(obj).closest('tr').attr('id');
			if(id==1)
				 $("#fieldTable tr").remove();
			else
			 $(obj).closest('tr').remove();
			 var rowIndex=$("#fieldTable tbody tr").length;
			 if(rowIndex==0)
				 $("#stockNumber").attr("disabled",false);
			}
		function addField()
		{
			$("#stockNumber").attr("disabled","disabled");
			var rowIndex=$("#fieldTable tbody tr").length+1;
			if(rowIndex==1)
			$("#fieldTable").append("<tr id="+rowIndex+"><td>自定义属性名称：<input name='fieldName"+rowIndex+"' id='fieldName"+rowIndex+"' type='text' size='25' maxlength='50' /></td>"
			         +"<td>自定义属性值：<input name='fieldValue"+rowIndex+"' id='fieldValue"+rowIndex+"' type='text' size='25' maxlength='50' />"
	          +"&nbsp;对应库存数量： <input name='stockNumber"+rowIndex+"' id='stockNumber"+rowIndex+"' type='text' size='25' maxlength='50' />"
	          +" <input type='button' value='全删'  class='button cyan medium' onclick='delField(this);'/></td></tr>");
			else
				$("#fieldTable").append("<tr id="+rowIndex+"><td/>"
				         +"<td>自定义属性值：<input name='fieldValue"+rowIndex+"' id='fieldValue"+rowIndex+"' type='text' size='25' maxlength='50' />"
		          +"&nbsp;对应库存数量： <input name='stockNumber"+rowIndex+"' id='stockNumber"+rowIndex+"' type='text' size='25' maxlength='50' />"
		          +" <input type='button' value='删除'  class='button cyan medium' onclick='delField(this);'/></td></tr>");
			//var intGridviewRowCount =$("table[id$='fieldTable']>tbody").children("tr").length;
			}
		function picFuzhi(){
			 var money=document.getElementById("supplierPrice").value;
			 if(money==""||isNaN(money)){
					alert("请输入正确的单价。");
					return;
			 }
			 var originalmoney=document.getElementById("originalPrice").value;
			 if(originalmoney==""||isNaN(originalmoney)){
					alert("请输入正确的原价。");
					return;
			 }
			 var type=document.getElementById("nodeId").value;
			 if(type==""||type==null){
					alert("请选择商品类别。");
					return;
			 }
			 var reserveFlag = document.getElementById("reserveFlag").value;
			 if(reserveFlag == '1'){
				 var reserveStartDate=document.getElementById("reserveStartDate").value;
				 if(reserveStartDate==""||reserveStartDate==null){
						alert("请选择预订开始日期。");
						return;
				 }
				 var reserveEndDate=document.getElementById("reserveEndDate").value;
				 if(reserveEndDate==""||reserveEndDate==null){
						alert("请选择预订最后日期。");
						return;
				 }
				 var reserveDate=document.getElementById("reserveDate").value;
				 if(reserveDate==""||reserveDate==null){
						alert("请选择预计送达日期。");
						return;
				 }
			 }else{
				 $("#reserveStartDate").val("");
				 $("#reserveEndDate").val("");
				 $("#reserveDate").val("");
			 }
			 var fieldList="";
			 var i=0;
		        var fieldName="";
			 $("#fieldTable tr").each(function(idx) {
			        // table1 下查找第 idx 个 tr，再查找 img
			        var trid=$("#fieldTable tr:eq(" + idx +")").attr("id");
			        if(trid==1)
			        	{
			        	fieldName=$("#fieldName" + trid).val();
			        	if(fieldName=="")
			        	{
			        		alert("请输入属性商品的名称。");
							return;
			        	}
			        	}
			        var stock=$("#stockNumber" + trid).val();
					 if(stock==""||isNaN(stock)){
							alert("请输入属性商品的库存。");
							return;
					 }
					 i++;
						//alert(data[a].wjbm);
						var name=fieldName+";"+$("#fieldValue" + trid).val()
						+";"+$("#stockNumber" + trid).val();
						if($("#fieldName" + trid).val()==""&&$("#fieldValue" + trid).val()==""&&$("#stockNumber" + trid).val()=="")
						{}
						else
							fieldList+=name+"@";
			    });
			 if(i<$("#fieldTable tr").length)
				 return;
			 $("#field").val(fieldList); 
			var idNew = $("#idNew").val();
			$.post('${ctx}/wjsc/getFileBmList/'+idNew,function(data, textStatus) {
				if(textStatus == 'success') {
					for(var a=0;a<data.length;a++){
						//alert(data[a].wjbm);
						$("#productPic" + a).val(data[a].wjbm);
					}
					
					editor1.sync();
					$("#myForm").submit();
					//document.getElementById("myForm").submit();
				}
			},"json"); 
		}
</SCRIPT>

<center style='padding-top:20px;padding-bottom:20px;'>
<form name="myForm" id="myForm" method="POST" action="${baseURL}/supplierProduct/saveProduct">
		<TABLE width='95%' class='table-border' cellpadding=0 cellspacing=0>
		<input type="hidden" name="id" value="${formdata.id}" />
		<input type="hidden" id="idNew" name="idNew" value="${idNew}" />
		<input name="productPic1" type="hidden" class="myInput" id="productPic0" value=""/>
		<input name="productPic2" type="hidden" class="myInput" id="productPic1" value=""/>
		<input name="productPic3" type="hidden" class="myInput" id="productPic2" value="" />
		<input name="productPic4" type="hidden" class="myInput" id="productPic3" value="" />
		<input name="productPic5" type="hidden" class="myInput" id="productPic4" value="" />
		<input name="field" type="hidden" class="myInput" id="field" value="" />
		<!-- <input type="button" value="fuzhi" onclick="picFuzhi();"> -->
		<TR>
			<TD class='tr-title' >&nbsp;&nbsp;&nbsp;商品管理</TD>
		</TR>
		<TR>
			<TD width='100%'>
				<TABLE width='100%' border=0 cellpadding=2 cellspacing=2 id="content-input">
					<TR>
						<TD width='150' align='right'>商品编号：</TD>
						<td align="left">${formdata.productCode}</td>
					</TR>
					<TR>
						<TD width='150' align='right'>商品名称 ：</TD>
						<td align="left"><input name="productName" type="text" id="productName" value="${formdata.productName}" size="70" maxlength="50" /></td>
					</TR>
					<TR>
						<TD width='150' align='right'>*商品所属分类：</TD>
						<td align="left" colspan="3"><input type="hidden" name="nodeId" id="nodeId" value="${formdata.nodeId}"/>
							<input name="selectedNodeName" id="selectedNodeName" type="text" readonly value="${formdata.selectedNodeName}" size="40" onclick="showMenu()"/>
							<div id="menuContent" class="menuContent" style="display:none; position: absolute;">
								<ul id="treeDemo" class="ztree" style="margin-top:0; width:300px;"></ul>
							</div>	
						</td>
					</TR>
					<TR>
						<TD width='150' align='right'>库存数量：</TD>
						<td align="left">
			  				<input name="stockNumber" id="stockNumber" type="text" id="stockNumber" value="${formdata.stockNumber}" size="25" maxlength="50" />
						</td>
					</TR>
					<TR>
						<TD width='150' align='right'>销售数量：</TD>
						<td align="left">${formdata.sellNumber}</td>
					</TR>
					<TR>
						<TD width='150' align='right'>商品介绍：</TD>
						<td>
							<link rel="stylesheet" href="${baseURL}/kindeditor417/themes/default/default.css" />
							<link rel="stylesheet" href="${baseURL}/kindeditor417/plugins/code/prettify.css" />
							<script charset="utf-8" src="${baseURL}/kindeditor417/kindeditor-all-min.js"></script>
							<script charset="utf-8" src="${baseURL}/kindeditor417/lang/zh_CN.js"></script>
							<script charset="utf-8" src="${baseURL}/kindeditor417/plugins/code/prettify.js"></script>
							<script>
								KindEditor.ready(function(K) {
									editor1 = K.create('textarea[name="productContent"]', {
										cssPath : '${baseURL}/kindeditor417/plugins/code/prettify.css',
										uploadJson : '${baseURL}/kindeditor417/jsp/upload_json.jsp',
										fileManagerJson : '${baseURL}/kindeditor417/jsp/file_manager_json.jsp',
										allowFileManager : true,
										afterCreate : function() {
											var self = this;
											K.ctrl(document, 13, function() {
												self.sync();
												K('form[name=myForm]')[0].submit();
											});
											K.ctrl(self.edit.doc, 13, function() {
												self.sync();
												K('form[name=myForm]')[0].submit();
											});
										}
									});
									prettyPrint();
								});
								
							</script>
					  		<textarea name="productContent" cols="60" rows="25" class="myInput" id="productContent">${formdata.productContent}</textarea>
					  </td>
					<TR>
						<TD width='150' align='right'>商品图片：</TD>
						<td>
							<!-- <div class="flash" id="fsUploadProgress"></div>
						    <div style="padding-left: 5px;">
							  	<span id="spanButtonPlaceholder"></span>
							  	<input id="btnCancel" type="button" value="取消" onclick="cancelQueue(upload);" disabled="disabled" style="margin-left: 2px; height: 22px; font-size: 8pt;" />
						  	</div> -->
						  	<iframe width=100% height=90 frameborder=0 id="scfj" scrolling=no src="${baseURL}/wjsc/query/${idNew}/update" onload="iFrameHeight1()"></iframe>
						</td>
					</TR>
					<tr>
					  <td width='150' align="right">货物原价：</td>
				      <td align="left">
				      <input name="originalPrice" id="originalPrice" type="text"
				      value="${formdata.originalPrice}" size="25" maxlength="50" />元（人民币）/例</td> 
				     <!-- <span id="supplierPrice">${formdata.supplierPrice}</span>元（人民币）</td> --> 
					</tr>
					<tr>
					  <td width='150' align="right">货物单价：</td>
				      <td align="left">
				      <input name="supplierPrice" id="supplierPrice" type="text"
				      value="${formdata.supplierPrice}" size="25" maxlength="50" />元（人民币）/例</td> 
				     <!-- <span id="supplierPrice">${formdata.supplierPrice}</span>元（人民币）</td> --> 
					</tr>
					<tr>
					  <td width='150' align="right">货物重量：</td>
				      <td align="left">
				      <input name="weight" id="weight" type="text"
				      value="${formdata.weight}" size="25" maxlength="50" />
				      <input name="weightUnit" id="weightUnit" type="text"
				      value="${formdata.weightUnit}" size="10" maxlength="50" />/例
				      <select name="weightUnitSelect" id="weightUnitSelect" onchange="$('#weightUnit').val($('#weightUnitSelect').val())">
				      	<option value="">预设单位..</option>
				      	<option value="千克" ${formdata.weightUnit=="千克"?"selected":""}>千克</option>
				      	<option value="克" ${formdata.weightUnit=="克"?"selected":""}>克</option>
				      	<option value="升" ${formdata.weightUnit=="升"?"selected":""}>升</option>
				      	<option value="毫升" ${formdata.weightUnit=="毫升"?"selected":""}>毫升</option>
				      	<option value="件" ${formdata.weightUnit=="件"?"selected":""}>件</option>
				      	<option value="包" ${formdata.weightUnit=="包"?"selected":""}>包</option>
				      	<option value="袋" ${formdata.weightUnit=="袋"?"selected":""}>袋</option>
			    	</select>
				      </td> 
				      </tr>
				      <tr>
					  <td width='150' align="right">商品品质：</td>
				      <td align="left">
				      	<input name="quality" id="quality" type="text" value="${formdata.quality}" size="25" maxlength="50" />
				      	<select name="qualitySelect" id="qualitySelect" style="width:100px" onchange="$('#quality').val($('#qualitySelect').val())">
				      		<option value="">预设类别..</option>
				      		<option value="无公害" ${formdata.quality=="无公害"?"selected":""}>无公害</option>
				      		<option value="绿色" ${formdata.quality=="绿色"?"selected":""}>绿色</option>
				      		<option value="有机" ${formdata.quality=="有机"?"selected":""}>有机</option>
				      		<option value="普通" ${formdata.quality=="普通"?"selected":""}>普通</option>
				      		<option value="精品" ${formdata.quality=="精品"?"selected":""}>精品</option>
				      		<option value="原装进口" ${formdata.quality=="原装进口"?"selected":""}>原装进口</option>
			    		</select>
				      </td> 
				      </tr>
				      
					<tr>
					  <td width='150' align="right">产地信息：</td>
				      <td align="left">
				      <input name="productPlace" id="productPlace" type="text" value="${formdata.productPlace}" size="25" maxlength="40" /></td> 
				     <!-- <span id="supplierPrice">${formdata.supplierPrice}</span>元（人民币）</td> --> 
					</tr>
					<tr>
					  <td width='150' align="right">商品类型：</td>
				      <td align="left">
				      <select name="virtualFlag" id="virtualFlag" style="width:100px">
				      	<option value="0" ${formdata.virtualFlag=="0"?"selected":""}>实物</option>
				      	<option value="1" ${formdata.virtualFlag=="1"?"selected":""}>非实物</option>
			    	</select></td> 
				     <!-- <span id="supplierPrice">${formdata.supplierPrice}</span>元（人民币）</td> --> 
					</tr>
						<tr>
					  <td width='150' align="right">是否预定商品：</td>
				      <td align="left">
				       <select name="reserveFlag" id="reserveFlag" style="width:100px" onclick="changeSelect()">
				      	<option value="0" ${formdata.reserveFlag=="0"?"selected":""}>非预定</option>
				      	<option value="1" ${formdata.reserveFlag=="1"?"selected":""}>预定</option>
			    	</select>
			    	<div id="reserve" style="display:none">
			    	预订开始日期：
			    	<input id="reserveStartDate" name="reserveStartDate" onclick="calendar.show(this);" value="${formdata.reserveStartFormatDate}" type="text" class="sell-textinput-02">
			    	预订最后日期：
			    	<input id="reserveEndDate" name="reserveEndDate" onclick="calendar.show(this);" value="${formdata.reserveEndFormatDate}" type="text" class="sell-textinput-02">
			    	预计送达日期：
			    	<input id="reserveDate" name="reserveDate" onclick="calendar.show(this);" value="${formdata.reserveFormatDate}" type="text" class="sell-textinput-02">
			    	</div>
			    	</td>
					</tr>
					<tr>
					<td width='150' align="right">
					<input type="button" value="添加属性"  class='button cyan medium' onclick="addField()"/>
					</td>
					</tr>
					<tr>
					 <td align="center" colspan="2">
					<div id="field" >
					<table id="fieldTable" name="fieldTable">
					<c:if test="${not empty productFieldList}">
					<% int i=1;%>
    		<c:forEach var="field" items="${productFieldList}">
    		<tr id="<%=i %>">
    		<% if(i==1){%>
    		<td>自定义属性名称：<input name='fieldName<%=i %>' id='fieldName<%=i %>' type='text' size='25' maxlength='50' value="${field.fieldName}"/></td>
			        <td> 自定义属性值：<input name='fieldValue<%=i %>' id='fieldValue<%=i %>' type='text' size='25' maxlength='50' value="${field.fieldValue}" />
	          对应库存数量： <input name='stockNumber<%=i %>' id='stockNumber<%=i %>' type='text' size='25' maxlength='50' value="${field.stockNumber}" />
	          <input type="button" value="全删"  class='button cyan medium' onclick="delField(this);"/>
	          </td>
	          <%}else{%>
	          <td/>
			        <td> 自定义属性值：<input name='fieldValue<%=i %>' id='fieldValue<%=i %>' type='text' size='25' maxlength='50' value="${field.fieldValue}" />
	          对应库存数量： <input name='stockNumber<%=i %>' id='stockNumber<%=i %>' type='text' size='25' maxlength='50' value="${field.stockNumber}" />
	          <input type="button" value="删除"  class='button cyan medium' onclick="delField(this);"/>
	          </td>
	          <%} %>
	          </tr>
	      	<% i++;%>
	      	</c:forEach>
	    </c:if>
					</table>
			    	</div>
					 </td>
					</tr>
					<tr> 
				      <td width='150' align="right">备注： </td>
				      <td>
				      <textarea name="remark" cols="50" rows="5" style='width:300px;border:1px solid #dddddd;col:10' id="remark">${formdata.remark}</textarea></td>
				    </tr>
				    <TR>
						<td height="65" align="center" colspan=2>
							<table width="200" border="0" cellspacing="0" cellpadding="0">
								<tr>
								  <td valign="middle">
								  	<input class="btnstyle" type="button" value="提交" onclick="picFuzhi()"/>
								  </td>
								  <td align="center" valign="middle" >&nbsp;</td>
								  <td valign="middle" >
								  	<input name="button" class="btnstyle" type="button" onclick="history.go(-1)" value="返回" />
								  </td>
								</tr>
							</table>
						</td>
					</TR>
					<tr>
					  <td colspan="4" align="center">&nbsp;</td>
				    </tr>
				</TABLE>
			</TD>
		</TR>
	</TABLE>
	</form>
</center>
<script>
changeSelect();
	function changeSelect()
	{
		var flag=$('#reserveFlag option:selected').val();
		if(flag==0)
			document.getElementById("reserve").style.display="none";
		else
			document.getElementById("reserve").style.display="block";
	}
	var i=0;
	
</script>
<%@ include file="../include/bottom.jsp" %>